package com.telecomyt.jwportal.activity.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.telecomyt.jwportal.R;
import com.telecomyt.jwportal.activity.fragment.adapter.ContentAdapter;
import com.telecomyt.jwportal.bean.UsersBean;

import java.util.List;


/**
 * @description java类作用
 * @date: $ $
 * @author: 程达
 */
public class DemoFragment extends Fragment {
    private RecyclerView mRecyclerView;
    private List<UsersBean.DeptsBean> bean;
    private FragmentActivity fragmentActivity;

    public DemoFragment(FragmentActivity fragmentActivity) {
        this.fragmentActivity = fragmentActivity;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_demo, container, false);
        bean = (List<UsersBean.DeptsBean>) getArguments().getSerializable("bean");
        mRecyclerView = view.findViewById(R.id.mRecyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        ContentAdapter contentAdapter = new ContentAdapter(R.layout.fragment_content_items);
        mRecyclerView.setAdapter(contentAdapter);
        contentAdapter.setNewData(bean);
        contentAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                fragmentActivity.showData(contentAdapter.getData().get(position).getDeptId(), true, contentAdapter.getData().get(position).getDeptName());
            }
        });
        return view;
    }
}